<template>
  <div>
    <el-dialog
      title="驳回原因"
      :visible="open"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="500px"
      append-to-body
      @close="cancel()"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="type == 1 || type == 2 ? rules : {}"
        label-width="80px"
      >
        <el-form-item v-if="type == 1 || type == 2" label="驳回原因" prop="uncheckReason">
          <el-input
            v-model="form.uncheckReason"
            maxlength="100"
            show-word-limit
            :rows="3"
            type="textarea"
            placeholder="请输入驳回原因"
          />
        </el-form-item>
        <div v-else style="white-space: pre-wrap">{{ form.uncheckReason }}</div>
      </el-form>
      <div slot="footer" class="dialog-footer" style="display: flex;justify-content: flex-end">
        <el-button v-if="type == 1 || type == 2" v-preventReClick @click="cancel">取 消</el-button>
        <el-button
          v-preventReClick
          type="primary"
          @click="submitForm"
          v-if="type == 1 || type == 2"
        >
          提 交
        </el-button>
        <el-button v-preventReClick @click="cancel" v-if="type == 3">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    open: Boolean,
    type: Number,
    item: Object
  },
  data() {
    return {
      // 表单参数
      form: {
        uncheckReason: undefined
      },
      // 表单校验
      rules: {
        uncheckReason: [
          { required: true, message: '驳回原因不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    open(e) {
      if (this.type == 1) {
        this.reset()
      }
      if (this.type == 2 || this.type == 3) {
        console.log(this.item, 'this.itemthis.item')
        this.form = this.item
      }
    }
  },
  mounted() {
  },
  methods: {
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$emit('update:open', false)
          this.$emit('refresh', this.form.uncheckReason)
        }
      })
    },
    // 表单重置
    reset() {
      this.resetForm('form')
      this.form = {
        uncheckReason: undefined
      }
    },
    cancel() {
      this.$emit('update:open', false)
      this.reset()
    }
  }
}
</script>
<style scoped lang="scss">
</style>
